/*
 * @Descripttion: 
 * @version: 
 * @Author: spring
 * @Date: 2022-04-16 22:36:06
 * @LastEditors: spring
 * @LastEditTime: 2022-04-18 22:44:38
 */
import { chatType } from "../types";
import { ADD } from "../common/constant";
import storage from '../utils/storage'

const listData: string = storage.getItem("chatDataList") || "";
const initState: chatType[] = listData ? JSON.parse(listData) : [];

interface chatActionType {
  type: "add";
  data: chatType;
}

export default function chatStacte(
  preState = initState,
  action: chatActionType
) {
  const { type, data } = action;
  switch (type) {
    case ADD: //增加
    storage.setItem("chatDataList", JSON.stringify([...preState, data]));
      return [...preState, data];
    default:
      return preState;
  }
}
